using System;
using System.Diagnostics;
using System.IO;
using System.Collections;
using System.Reflection;
using Microsoft.RuleEngine;
using Microsoft.BizTalk.RuleEngineExtensions;


namespace DeployRules
{
    partial class App
    {
        /// <summary>
        /// The Import method imports specified vocabulary(ies) and/or policy(ies) 
        /// from BRL XML files into the rule engine database. 
        /// </summary>
        /// <returns>0 for success, -1 for failure</returns>
        private static int Import()
        {
            int result = 0;

            // RuleSetDeploymentDriver has the following important methods 
            // Deploy, Undeploy, ImportAndPublishFileRuleStore, ExportVocabularyToFileRuleStore, ExportRuleSetToFileStore
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();

            // SqlRuleStore - gives access t the rule engine database
            SqlRuleStore sqlRuleStore = (SqlRuleStore)dd.GetRuleStore();

            foreach (string filename in App.files)
            {
                //Writes to command line, and optionally logs to log file
                LogMessage(null); //Empty line
                LogMessage("Processing file: " + filename);

                //need to verify that the input files
                if (isPolicyImport)
                {
                    if (VerifyFilePolicyType(filename))
                        ImportPolicy(filename);
                    else
                        LogMessage("** Invalid Policy file type: [" + filename + "]");

                }
                if (isVocabularyImport)
                {
                    if (VerifyFileVocabularyType(filename))
                        ImportVocabulary(filename);
                    else
                    {
                        LogMessage("*** Invalid vocabulary file type: [" + filename + "]");
                    }
                }

                LogMessage(null);
            }
            return result;
        }


        /// 
        ///this will return true or false based on the content of the file being asked to be imported.
        private static bool VerifyFilePolicyType(string filename)
        {
            bool bReturn = false;

            FileRuleStore fileRuleStore = new FileRuleStore(filename);
            RuleSetInfoCollection ruleSetColl = fileRuleStore.GetRuleSets(RuleStore.Filter.All);
            if (ruleSetColl.Count > 0) bReturn = true;
            return bReturn;
        }
        /// 
        ///this will return true or false based on the content of the file being asked to be imported.
        private static bool VerifyFileVocabularyType(string filename)
        {
            bool bReturn = false;
            FileRuleStore fileRuleStore = new FileRuleStore(filename);
            VocabularyInfoCollection vocabInfoColl = fileRuleStore.GetVocabularies(RuleStore.Filter.All);
            if (vocabInfoColl.Count > 0) bReturn = true;
            return bReturn;
        }

        private static int ImportPolicy(string filename)
        {
            int result = 0;
            // FileRuleStore - gives access to the BRL (XML) file containing policies and vocabularies
            FileRuleStore fileRuleStore = null;

            // RuleSetDeploymentDriver has the following important methods 
            // Deploy, Undeploy, ImportAndPublishFileRuleStore, ExportVocabularyToFileRuleStore, ExportRuleSetToFileStore
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();

            // SqlRuleStore - gives access t the rule engine database
            SqlRuleStore sqlRuleStore = (SqlRuleStore)dd.GetRuleStore();

            if (importFlag && !publishPolicy)
            {
                fileRuleStore = new FileRuleStore(filename);
                RuleSetInfoCollection ruleSetColl = fileRuleStore.GetRuleSets(RuleStore.Filter.All);

                foreach (RuleSetInfo ruleSetInfo in ruleSetColl)
                {
                    RuleSet ruleSet = fileRuleStore.GetRuleSet(ruleSetInfo);
                    sqlRuleStore.Add(ruleSet, false);
                    LogMessage("Policy name: " + ruleSet.Name);
                    LogMessage("Adding policy");
                }
            }

            else if (importFlag && publishPolicy)
            {
                dd.ImportAndPublishFileRuleStore(filename);
            }

            return result;
        }
  
        private static int ImportVocabulary(string filename)
        {
            int result = 0;

            // FileRuleStore - gives access to the BRL (XML) file containing policies and vocabularies
            FileRuleStore fileRuleStore = null;

            // RuleSetDeploymentDriver has the following important methods 
            // Deploy, Undeploy, ImportAndPublishFileRuleStore, ExportVocabularyToFileRuleStore, ExportRuleSetToFileStore
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();

            // SqlRuleStore - gives access t the rule engine database
            SqlRuleStore sqlRuleStore = (SqlRuleStore)dd.GetRuleStore();




            if (importFlag && !publishVocabulary)
            {
                //Create a FileRuleStore object based on the file name
                fileRuleStore = new FileRuleStore(filename);

                VocabularyInfoCollection vocabInfoColl = fileRuleStore.GetVocabularies(RuleStore.Filter.All);

                foreach (VocabularyInfo vocabInfo in vocabInfoColl)
                {
                    Vocabulary vocab = fileRuleStore.GetVocabulary(vocabInfo);
                    string vocabularyNameWithVer = string.Format("{0}.{1}.{2}", vocabInfo.Name, vocabInfo.MajorRevision, vocabInfo.MinorRevision);
                    sqlRuleStore.Add(vocab, false);
                    LogMessage("Adding vocabulary " + vocabularyNameWithVer);
                }


            }
            else if (importFlag && publishVocabulary)
            {

                //Import vocabularies before importing policies
                //Get VocabularyInfoCollection object based on the file
                fileRuleStore = new FileRuleStore(filename);
                VocabularyInfoCollection vocabularyInfoList = fileRuleStore.GetVocabularies(RuleStore.Filter.All);
                foreach (VocabularyInfo vocabularyInfo in vocabularyInfoList)
                {
                    string vocabularyNameWithVer = string.Format("{0}.{1}.{2}", vocabularyInfo.Name, vocabularyInfo.MajorRevision, vocabularyInfo.MinorRevision);
                    ExtractVocabularyNameMajorMinor(vocabularyNameWithVer);
                    VocabularyInfo vi = new VocabularyInfo(App.vocabularyName, App.vocabularyMajorVer, App.vocabularyMinorVer);
                    Vocabulary oVoc = fileRuleStore.GetVocabulary(vi);

                    if (publishVocabulary)
                    {
                        LogMessage("Publishing vocabulary " + vocabularyNameWithVer);
                        sqlRuleStore.Add(oVoc, App.publishVocabulary);
                    }
                    else
                    {
                        LogMessage("Adding vocabulary. " + vocabularyNameWithVer);
                        sqlRuleStore.Add(oVoc);
                    }

                }
            }


            return result;
        }

        /// <summary>
        /// The Export method exports specified vocabulary(ies) and/or policy(ies) 
        /// from the rule engine database to an output BRL XML file . 
        /// </summary>
        /// <returns>0 for success, -1 for failure</returns>
        private static int Export()
        {
            // RuleSetDeploymentDriver has the following important methods 
            // Deploy, Undeploy, ImportAndPublishFileRuleStore, ExportVocabularyToFileRuleStore, ExportRuleSetToFileStore
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();

            // SqlRuleStore - gives access t the rule engine database
            SqlRuleStore sqlRuleStore = (SqlRuleStore)dd.GetRuleStore();


            FileRuleStore expfileRuleStore = null;
            string fileName = null;
            int result = 0;
            VocabularyInfoCollection vocabularyInfoList = null;
            RuleSetInfoCollection ruleSetInfoList = null;

            if (App.files.Count > 0)
                fileName = App.files[0].ToString();
            else
                fileName = "Output_" + System.Guid.NewGuid().ToString() + ".xml";

            if (File.Exists(fileName))
            {
                string message = String.Format("{0} already exists. Overwriting...\r\n", fileName);
                LogMessage(message);
                File.Delete(fileName);
            }
            expfileRuleStore = new FileRuleStore(fileName);

            if (exportAllVocabularies == true || vocabularyName != null)
            {
                if (exportAllVocabularies)
                {
                    LogMessage("Exporting all vocabularies");
                    LogMessage("=================================");
                }

                if (vocabularyName != null)
                    vocabularyInfoList = sqlRuleStore.GetVocabularies(vocabularyName, RuleStore.Filter.All);
                else
                    vocabularyInfoList = sqlRuleStore.GetVocabularies(RuleStore.Filter.All);

                bool vocabExported = false;

                foreach (VocabularyInfo vocabularyInfo in vocabularyInfoList)
                {
                    vocabExported = false;

                    Vocabulary vocabulary = sqlRuleStore.GetVocabulary(vocabularyInfo);

                    LogMessage("Inspecting vocabulary " + vocabularyInfo.Name + "." + vocabularyInfo.MajorRevision + "." + vocabularyInfo.MinorRevision);

                    if (exportToAPath)
                    {
                        string vocabFileName = fileName + vocabulary.Name + ".xml";

                        FileRuleStore fileStore = new FileRuleStore(vocabFileName);

                        if (vocabularyInfo.ModifiedBy != "Microsoft" && (!vocabulary.Name.StartsWith("ESB.")))
                        {
                            fileStore.Add(vocabulary);
                            vocabExported = true;
                        }
                    }
                    else
                    {
                        expfileRuleStore.Add(vocabulary);
                        vocabExported = true;
                    }

                    if (vocabExported)
                        LogMessage("Exporting vocabulary " + vocabularyInfo.Name + "." + vocabularyInfo.MajorRevision + "." + vocabularyInfo.MinorRevision);
                }

                if (exportAllVocabularies)
                    LogMessage("=================================\r\n");
            }

            if (exportAllPolicies == true || policyName != null)
            {
                if (exportAllPolicies)
                {
                    LogMessage("Exporting all polices");
                    LogMessage("=================================");
                }

                if (policyName != null)
                    ruleSetInfoList = sqlRuleStore.GetRuleSets(policyName, RuleStore.Filter.All);
                else
                    ruleSetInfoList = sqlRuleStore.GetRuleSets(RuleStore.Filter.All);

                foreach (RuleSetInfo ruleSetInfo in ruleSetInfoList)
                {
                    LogMessage("Exporting policy " + ruleSetInfo.Name + "." + ruleSetInfo.MajorRevision + "." + ruleSetInfo.MinorRevision);
                    RuleSet rs = sqlRuleStore.GetRuleSet(ruleSetInfo);

                    if (exportToAPath)
                    {
                        string policyFileName = fileName + ruleSetInfo.Name + ".xml";

                        FileRuleStore fileStore = new FileRuleStore(policyFileName);

                        fileStore.Add(rs);
                    }
                    else
                        expfileRuleStore.Add(rs);
                }

                if (exportAllPolicies)
                    LogMessage("=================================\r\n");
            }

            if (exportAllVocabularies || exportAllPolicies || (policyName != null) || (vocabularyName != null))
            {
                if (ruleSetInfoList == null)
                    LogMessage("Check Output Directory: " + fileName + "\r\n");
                else if ((ruleSetInfoList.Count > 0) && (ruleSetInfoList.Count > 0))
                    LogMessage("Output file name: " + fileName + "\r\n");
                else
                {
                    if (policyName != null)
                    {
                        LogMessage("Could not find the policy " + policyName);
                        result = -1;
                    }

                    if (vocabularyName != null)
                    {
                        LogMessage("Could not find the vocabulary " + vocabularyName);
                        result = -1;
                    }
                }
            }
            else
            {
                LogMessage("Use /P or/and /V flags");
                result = -1;
            }

            return result;
        }

        /// <summary>
        /// The Deploy method deploys specified policy(ies)
        /// </summary>
        /// <returns>0 for success, -1 for failure</returns>
        private static int DeployPolicy()
        {
            int result = 0;
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rdd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();

            // SqlRuleStore - gives access t the rule engine database
            SqlRuleStore sqlRuleStore = (SqlRuleStore)rdd.GetRuleStore();

            RuleSetInfoCollection ruleSetInfoList = null;
            for (int i = 0; i < policies.Count; i++)
            {
                string policyNameWithVer = policies[i].ToString();
                if (policyNameWithVer != null && App.isSingleDeployment == false)
                {
                    ruleSetInfoList = sqlRuleStore.GetRuleSets(policyNameWithVer, RuleStore.Filter.All);

                    foreach (RuleSetInfo oRule in ruleSetInfoList)
                    {
                        if (!rdd.IsRuleSetDeployed(oRule))//if it has not been deployed previously
                        {
                            RuleSet rs = sqlRuleStore.GetRuleSet(oRule);
                            policyNameWithVer = string.Format("{0}.{1}.{2}", rs.Name, rs.CurrentVersion.MajorRevision,
                                                              rs.CurrentVersion.MinorRevision);

                            ExtractPolicyNameMajorMinor(policyNameWithVer);
                            RuleSetInfo rsi = new RuleSetInfo(App.policyName, App.policyMajorVer, App.policyMinorVer);

                            //what if it is not published
                            LogMessage("Deploying the policy " + App.policyName + "." + App.policyMajorVer + "." + App.policyMinorVer);
                            rdd.Deploy(rsi);
                        }
                    }
                }
                if (App.isSingleDeployment)
                {
                    //need to check that only one policy is being deployed. as opposed as ALL versions of a policy
                    ExtractPolicyNameMajorMinor(policyNameWithVer);
                    RuleSetInfo rsi = new RuleSetInfo(App.policyName, App.policyMajorVer, App.policyMinorVer);

                    //what if it is not published
                    LogMessage("Deploying the policy " + App.policyName + "." + App.policyMajorVer + "." + App.policyMinorVer);
                    rdd.Deploy(rsi);

                }


            }

            return result;
        }


        /// <summary>
        /// The UndeployPolicy method undeploys specified policy(ies, and optionally 
        /// deletes them from the rule engine database. 
        /// </summary>
        /// <returns>0 for success, -1 for failure</returns>
        private static int UndeployPolicy()
        {
            int result = 0;
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rdd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            SqlRuleStore sqlRuleStore = (SqlRuleStore)rdd.GetRuleStore();

            RuleSetInfoCollection ruleSetInfoList = null;
            for (int i = 0; i < policies.Count; i++)
            {
                string policyNameWithVer = policies[i].ToString();
                if (policyNameWithVer != null && App.isSingleDeployment == false)
                {
                    ruleSetInfoList = sqlRuleStore.GetRuleSets(policyNameWithVer, RuleStore.Filter.All);

                    foreach (RuleSetInfo oRule in ruleSetInfoList)
                    {
                        RuleSet rs = sqlRuleStore.GetRuleSet(oRule);
                        policyNameWithVer = string.Format("{0}.{1}.{2}", rs.Name, rs.CurrentVersion.MajorRevision,
                                                          rs.CurrentVersion.MinorRevision);

                        ExtractPolicyNameMajorMinor(policyNameWithVer);
                        if (rdd.IsRuleSetDeployed(oRule)) //if it has not been deployed previously
                        {
                            //undeploy before deleting it from the rule
                            LogMessage("Undeploying the policy " + App.policyName + "." + App.policyMajorVer + "." + App.policyMinorVer);
                            rdd.Undeploy(oRule);
                        }
                    }
                }
                else
                {
                    //remove single policy with version on it.
                    //need to check that only one policy is being deployed. as opposed as ALL versions of a policy
                    ExtractPolicyNameMajorMinor(policyNameWithVer);
                    RuleSetInfo rsi = new RuleSetInfo(App.policyName, App.policyMajorVer, App.policyMinorVer);

                    //what if it is not published
                    LogMessage("Undeploying the policy " + App.policyName + "." + App.policyMajorVer + "." + App.policyMinorVer);
                    rdd.Undeploy(rsi);
                }
            }
            return result;
        }

        /// <summary>
        /// The RemovePolicies method removes specified policy(ies, and optionally 
        /// deletes them from the rule engine database. 
        /// </summary>
        /// <returns>0 for success, -1 for failure</returns>
        private static int RemovePolicies()
        {
            int result = 0;
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rdd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            SqlRuleStore sqlRuleStore = (SqlRuleStore)rdd.GetRuleStore();

            LogMessage("");
            RuleSetInfoCollection ruleSetInfoList = null;
            for (int i = 0; i < policies.Count; i++)
            {
                string policyNameWithVer = policies[i].ToString();
                if (policyNameWithVer != null && App.isSingleDeployment == false)
                {
                    ruleSetInfoList = sqlRuleStore.GetRuleSets(policyNameWithVer, RuleStore.Filter.All);

                    foreach (RuleSetInfo oRule in ruleSetInfoList)
                    {
                        if (rdd.IsRuleSetDeployed(oRule)) //if it has not been deployed previously
                        {
                            //undeploy before deleting it from the rule
                            LogMessage("undeploying the policy " + App.policyName + "." + App.policyMajorVer + "." + App.policyMinorVer);
                            rdd.Undeploy(oRule);
                        }


                        //now add the logic to remove this version.

                        RuleSet rs = sqlRuleStore.GetRuleSet(oRule);
                        policyNameWithVer = string.Format("{0}.{1}.{2}", rs.Name, rs.CurrentVersion.MajorRevision,
                                                          rs.CurrentVersion.MinorRevision);

                        ExtractPolicyNameMajorMinor(policyNameWithVer);
                        RuleSetInfo rsi = new RuleSetInfo(App.policyName, App.policyMajorVer, App.policyMinorVer);

                        sqlRuleStore.Remove(rsi);
                        LogMessage("Removing the policy " + policyNameWithVer);

                    }
                }
                else
                {
                    //remove single policy
                    ExtractPolicyNameMajorMinor(policyNameWithVer);
                    RuleSetInfo rsi = new RuleSetInfo(App.policyName, App.policyMajorVer, App.policyMinorVer);
                    sqlRuleStore.Remove(rsi);
                    LogMessage("Removing the policy " + policyNameWithVer);
                }
            }
            return result;
        }


        /// <summary>
        /// The RemoveVocabulary method removes specified vocabulary(ies)
        /// from the rule engine database. 
        /// </summary>
        /// <returns>0 for success, -1 for failure</returns>
        private static int RemoveVocabulary()
        {
            int result = 0;
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rdd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            RuleStore sqlRuleStore = rdd.GetRuleStore();


            VocabularyInfoCollection ruleSetInfoList = null;
            for (int i = 0; i < vocabularies.Count; i++)
            {
                string vocabularyNameWithVer = vocabularies[i].ToString();

                ruleSetInfoList = sqlRuleStore.GetVocabularies(vocabularyNameWithVer, RuleStore.Filter.All);


                foreach (VocabularyInfo oRule in ruleSetInfoList)
                {
                    Vocabulary rs = sqlRuleStore.GetVocabulary(oRule);
                    vocabularyNameWithVer = string.Format("{0}.{1}.{2}", rs.Name, rs.CurrentVersion.MajorRevision, rs.CurrentVersion.MinorRevision);
                    Trace.WriteLine(string.Format("bts- oRule.Name = [{0}]", oRule.Name));
                    ExtractVocabularyNameMajorMinor(vocabularyNameWithVer);
                    LogMessage("Removing the vocabulary " + vocabularyNameWithVer);
                    VocabularyInfo vi = new VocabularyInfo(App.vocabularyName, App.vocabularyMajorVer, App.vocabularyMinorVer);
                    sqlRuleStore.Remove(vi);
                }

            }

            return result;
        }



        /// <summary>
        /// The ShowHelp method displays the syntax for using the DeployRules utility
        /// </summary>
        /// 
        private static void ShowHelp()
        {
            /*
			 
            BizTalk 2006 Rule Deployment Tool v1.2

            DESCRIPTION
            ========================================
            Imports policies and vocabularies from BRL files into the rule engine database
            Exports vocabularies and policies from rule engine database to BRL files


            SYNTAX
            ========================================
            Syntax for importing rules from BRL files:

                    deployrules.exe /I file(s) [/P] [/D] [/R]
                            /I - Import Policies ONLY
                            /M - Import Vocabularies ONLY
                            /P - Publish the imported policy
                            /D - Deploy the imported policy

            Syntax for exporting rules to BRL files:

                    deployrules.exe /e [/P[:policy name]] or/and [/V[:vocabulary name]] oupu
            tfilename
                            /E - Export
                            /P - Policy
                            /V - Vocabulary

            To display this message:
                    deployrules.exe /?
                    deployrules.exe /h

            EXAMPLES
            ========================================
            deployrules.exe /i input.xml
            deployrules.exe /i input*.xml
            deployrules.exe /i input?.xml
            deployrules.exe /i input.xml input2.xml
            deployrules.exe /i input.xml /p
            deployrules.exe /i input.xml /d
            deployrules.exe /e /p output.xml
            deployrules.exe /e /p:MyPolicy output.xml
            deployrules.exe /e /v output.xml
            deployrules.exe /e /v:MyVocabulary output.xml
            deployrules.exe /e /p /v output.xml
            deployrules.exe /e /p:MyPolicy /v:MyVocabulary output.xml
            deployrules.exe /d /p:MyPolicy
            deployrules.exe /d /p:MyPolicy /p:MySecondPolicy
            deployrules.exe /u /p:MyPolicy
            deployrules.exe /u /p:MyPolicy /p:MySecondPolicy
            deployrules.exe /u /p:MyPolicy /r
            deployrules.exe /r /p:MyPolicy
            deployrules.exe /r /p:MyPolicy /p:MySecondPolicy
            deployrules.exe /r /p:MyPolicy /v:MyVocabulary
            deployrules.exe /r /v:MyVocabulary
            */

            Console.WriteLine("DESCRIPTION");
            Console.WriteLine("========================================");
            Console.WriteLine("Imports policies and vocabularies from BRL files into the rule engine database");
            Console.WriteLine("Exports vocabularies and policies from rule engine database to BRL files\r\n");
            Console.WriteLine();

            Console.WriteLine("SYNTAX");
            Console.WriteLine("========================================");
            Console.WriteLine("Syntax for importing rules from BRL files:\r\n");
            Console.WriteLine("deployrules.exe /[I|M] file(s) [/P] [/D] [/R] [L:log file name]");
            Console.WriteLine("\t/I - Import Policies ONLY");
            Console.WriteLine("\t/M - Import Vocabularies ONLY");
            Console.WriteLine("\t/P - Publish the imported policy");
            Console.WriteLine("\t/D - Deploy the imported policy\r\n");
            Console.WriteLine("----------------------------------------");

            Console.WriteLine("Syntax for exporting rules to BRL files:\r\n");
            Console.WriteLine("deployrules.exe /E [/P[:policy name]] or/and [/V[:vocabulary name]] [L:log file name] ouputfilename");
            Console.WriteLine("\t/E - Export");
            Console.WriteLine("----------------------------------------");

            Console.WriteLine("Syntax for deploying policies:");
            Console.WriteLine("deployrules.exe /D /P:policyname [/P:onemorepolicy][L:log file name]");
            Console.WriteLine("\t/D - Deploy");
            Console.WriteLine("----------------------------------------");

            Console.WriteLine("Syntax for undeploying policies:");
            Console.WriteLine("deployrules.exe /U /P:policyname [/R] [/P:onemorepolicy] [L:log file name]");
            Console.WriteLine("\t/U - Undeploy");
            Console.WriteLine("\t/R - Remove");
            Console.WriteLine("----------------------------------------");


            Console.WriteLine("Syntax for removing policies and vocabularies :");
            Console.WriteLine("\tdeployrules.exe /R /p:policyname [/p:onemorepolicy] [/v:Vocabulary Name] [L:log file name]");
            Console.WriteLine("\t/R - Remove");
            Console.WriteLine("----------------------------------------");

            Console.WriteLine("To display this message:");
            Console.WriteLine("\tdeployrules.exe /?");
            Console.WriteLine("\tdeployrules.exe /h");
            Console.WriteLine();
            Console.WriteLine("========================================\r\n");

            Console.WriteLine("EXAMPLES");
            Console.WriteLine("========================================");
            Console.WriteLine("deployrules.exe /i input.xml");
            Console.WriteLine("deployrules.exe /i input*.xml");
            Console.WriteLine("deployrules.exe /i input?.xml");
            Console.WriteLine("deployrules.exe /i input.xml input2.xml");
            Console.WriteLine("deployrules.exe /i input.xml /p");
            Console.WriteLine("deployrules.exe /i input.xml /d");
            Console.WriteLine("deployrules.exe /i input.xml /d /l:MyLog.txt");
            Console.WriteLine("deployrules.exe /e /p output.xml");
            Console.WriteLine("deployrules.exe /e /p:MyPolicy output.xml");
            Console.WriteLine("deployrules.exe /e /v output.xml");
            Console.WriteLine("deployrules.exe /e /v:MyVocabulary output.xml");
            Console.WriteLine("deployrules.exe /e /p /v output.xml");
            Console.WriteLine("deployrules.exe /e /p:MyPolicy /v:MyVocabulary output.xml");
            Console.WriteLine("deployrules.exe /e /p:MyPolicy /v:MyVocabulary /l:MyLog.txt output.xml");
            Console.WriteLine("deployrules.exe /d p:/MyPolicy");
            Console.WriteLine("deployrules.exe /d p:/MyPolicy /p:MySecondPolicy");
            Console.WriteLine("deployrules.exe /u /p:MyPolicy");
            Console.WriteLine("deployrules.exe /u /p:MyPolicy /p:MySecondPolicy");
            Console.WriteLine("deployrules.exe /u /p:MyPolicy /r");
            Console.WriteLine("deployrules.exe /u /p:MyPolicy /r /l:MyLog.txt");
            Console.WriteLine("deployrules.exe /r /p:MyPolicy");
            Console.WriteLine("deployrules.exe /r /p:MyPolicy /v:MyVocabulary");
            Console.WriteLine("deployrules.exe /r /v:MyVocabulary");

            Console.WriteLine("---------------------------------------------------------------------");
            Console.WriteLine("Customizations added by Monish Nagisetty on 9/27/2007");
            Console.WriteLine("---------------------------------------------------------------------");

            Console.WriteLine("deployrules.exe /d /p:* (Deploys all versions of existing published policies)");
            Console.WriteLine("deployrules.exe /e /p c:\\ (Exports policies to a directory)");
            Console.WriteLine("deployrules.exe /e /v c:\\ (Exports vocabularies to a directory)");
            Console.WriteLine("deployrules.exe /r /p:* (Removes all policies)");
            Console.WriteLine("deployrules.exe /r /v:* (Removes all vocabularies)");
            Console.WriteLine("deployrules.exe /u /p:* (Undeploys all policies)");
            Console.WriteLine("deployrules.exe /m c:\\temp\\*.xml (imports all vocabularies ONLY)");
            Console.WriteLine("deployrules.exe /i c:\\temp\\*.xml (imports all policies ONLY)");
            Console.WriteLine("deployrules.exe /i /p c:\\temp\\*.xml (imports and publishes policies ONLY)");
            Console.WriteLine("deployrules.exe /m /p c:\\temp\\*.xml (imports and publishes vocabularies ONLY)");
        }
    }
}
